package pdm.traj.part.impl;

import java.util.ArrayList;
import java.util.List;

import pdm.traj.entity.PartInfo;
import pdm.traj.entity.TrackPoint2;
import pdm.traj.entity.TrajQuery;
import pdm.traj.part.PartPlan;

public class PartPlanUidAvg extends PartPlan {
	public static final String TAG = "PartPlanUidAvg";
	private String name;
	private String comment;
//	private List<String> ips;
//	private List<String> ports;
//	private int nodeNum = -1;
	
	@Override
	public PartInfo getPartInfoByTP(TrackPoint2 tp) {
		PartInfo pi = new PartInfo();
		if (tp == null) {
			System.err.println(TAG + ": getPartInfoByTP(): tp null value");
			return null;
		} else {
			char c = tp.getId().charAt(tp.getId().length() - 1);
			int index = (int) c % nodeNum;
			pi.setIp(ips.get(index));
			pi.setPort(ports.get(index));
		}
		return pi;
	}

    @Override
    public List<PartInfo> getPartInfoBySid(String sid) {
        return getAllPartInfo();
    }

    @Override
	public List<PartInfo> getPartInfoByQuery(TrajQuery query) {
		return getAllPartInfo();
	}
	
	@Override
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

//	@Override
//	public String getKeyPrefix() {
//		return TAG + "_" + name;
//	}

	public List<String> getIps() {
		return ips;
	}

	public void setIps(List<String> ips) {
		this.ips = ips;
	}

	public List<String> getPorts() {
		return ports;
	}

	public void setPorts(List<String> ports) {
		this.ports = ports;
	}

	@Override
	protected void initPlan() {
//		if (ips == null || ports == null) {
//			System.err.println(TAG + ": init(): ips or ports null value");
//			return;
//		}
//		if (ips.size() == 0 || ports.size() == 0) {
//			System.err.println(TAG + ": init(): ips or ports no entry");
//			return;
//		}
//		if (ips.size() != ports.size()) {
//			System.err.println(TAG + ": init(): ips and ports size not equal");
//			return;
//		}
//		nodeNum = ips.size();
//		for (int i = 0; i < nodeNum; i++) {
//			PartInfo pi = new PartInfo(ips.get(i), ports.get(i));
//			partInfo.add(pi);
//		}
	}
	
}
